new Vue({
    el: '#app',
    data: {
        // 加载
        loading: false,
        // 用户信息
        userInfo: userInfo != null ? userInfo : {
            id: null,
            nickname: "未登录"
        },
        images: [
            '../../imgs/0.jpg',
            '../../imgs/1.jpg',
            '../../imgs/2.jpg',
            '../../imgs/3.jpg',
            '../../imgs/4.jpg',
        ],
        items: ["我的题目", "全站题目", "练习题目", "添加题目"]
    },
    methods: {
        logout() {
            //发送Ajax请求
            this.loading = true;
            const url = prefixUrl + "/user/user/logout";
            axios.get(url).then((resp) => {
                const result = resp.data;

                if (result.code === resultConstant.success) {
                    // 设置显示的昵称
                    this.userInfo = {
                        id: null,
                        nickname: "未登录"
                    }
                    showMsg(this, "已退出登录");
                    // 删除localStorage存储的用户信息
                    localStorage.removeItem(localStorageKey.userInfo);
                    localStorage.removeItem(localStorageKey.token);
                    // 清空Session storage
                    sessionStorage.clear();

                } else {
                    showMsg(this, result.msg)
                }
            }).catch((error) => {
                showMsg(this, error)
            }).finally(() => {
                this.loading = false;
            });
        },
        login() {
            location.href = "login.html";
        },
        toMe() {
            location.href = "me.html";
        },
        toNoteManage() {
            location.href = "note_manage.html";
        },
        toCategoryManage() {
            location.href = "category_manage.html";
        }
    }
});